/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.mortbay.jetty.pico.entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Hnmtuan
 */
@Entity
@Table(name = "saved")
@NamedQueries({
    @NamedQuery(name = "Saved.findAll", query = "SELECT s FROM Saved s"),
    @NamedQuery(name = "Saved.findByCustomer", query = "SELECT s FROM Saved s WHERE s.savedPK.customer = :customer"),
    @NamedQuery(name = "Saved.findByItem", query = "SELECT s FROM Saved s WHERE s.savedPK.item = :item"),
    @NamedQuery(name = "Saved.findByCategory", query = "SELECT s FROM Saved s WHERE s.savedPK.category = :category"),
    @NamedQuery(name = "Saved.findByUpdateDate", query = "SELECT s FROM Saved s WHERE s.updateDate = :updateDate")})
public class Saved implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected SavedPK savedPK;
    @Column(name = "UpdateDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateDate;
    @JoinColumn(name = "Customer", referencedColumnName = "IdCus", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Customer customer1;
    @JoinColumns({
        @JoinColumn(name = "Item", referencedColumnName = "IdItem", insertable = false, updatable = false),
        @JoinColumn(name = "Category", referencedColumnName = "Category", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Item item1;

    public Saved() {
    }

    public Saved(SavedPK savedPK) {
        this.savedPK = savedPK;
    }

    public Saved(String customer, String item, String category) {
        this.savedPK = new SavedPK(customer, item, category);
    }

    public SavedPK getSavedPK() {
        return savedPK;
    }

    public void setSavedPK(SavedPK savedPK) {
        this.savedPK = savedPK;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public Customer getCustomer1() {
        return customer1;
    }

    public void setCustomer1(Customer customer1) {
        this.customer1 = customer1;
    }

    public Item getItem1() {
        return item1;
    }

    public void setItem1(Item item1) {
        this.item1 = item1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (savedPK != null ? savedPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Saved)) {
            return false;
        }
        Saved other = (Saved) object;
        if ((this.savedPK == null && other.savedPK != null) || (this.savedPK != null && !this.savedPK.equals(other.savedPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.mortbay.jetty.pico.entities.Saved[savedPK=" + savedPK + "]";
    }

}
